<?php

header("Content-type:text/html; charset=utf-8;");
require '../../../ppf/fun.php';
require '../../../ppf/pdo_mysql.php';
require '../../../ppf/zip.php';
/* p($_POST);
  var_dump(json_decode($_POST['attachment']));
  exit; */
$pd = new pdo_mysql();
$zip = new PHPZip();
session_start();

if (empty($_SESSION['uid'])) {
    $tips = array(
        'tips' => '请登录后再进行操作',
        'url' => 'index.php'
    );
    $tips = urlencode(serialize($tips));
    header('Location:/tips.php?gets=' . $tips);
    exit;
}
if(empty($_GET['id'])){
    echo "无效参数";exit;
}
$strID=rtrim($_GET["id"],",");
$files=$pd->db->query("select attachment_id from file_upload where id in({$strID})")->fetchAll(PDO::FETCH_ASSOC);
$dir='/upload/file_fend_attachment/';
$dir_root=$_SERVER['DOCUMENT_ROOT'];
foreach ($files as $file) {
    $attachment_id=  rtrim($file['attachment_id'],",");
    $id_arr=  explode(",", $attachment_id);
    foreach ($id_arr as $id) {
        $dirs[]=$dir_root.$dir.$id."/";
    }
}
$zip->ZipAndDownload($dirs);
exit;
?>